#coding='utf-8'
import pika



# 有密码
credentials = pika.PlainCredentials("admin", "admin")
connection = pika.BlockingConnection(pika.ConnectionParameters(
    host='172.16.1.120',
    port=5672,virtual_host='devHost',
    credentials=credentials))

channel = connection.channel()

# 设置订阅模式
exchange_name = 'test_direct'
channel.exchange_declare(exchange=exchange_name, durable=True, exchange_type='direct')
# 创建一个队列
# channel.queue_declare(queue='hello',durable=True)

# 发送数据
data = '{"message":"success","status":200,"data":null}'
channel.basic_publish(
    exchange=exchange_name,
    routing_key='test_queue',  # 消息队列名称
    body=data,  # 发送的数据
)
print(f" [x] Sent '{data}'")

connection.close()